Skip to content

Conversation

tzanko-matev
Copy link
Contributor

No description provided.

@tzanko-matev tzanko-matev changed the base branch from main to errors-and-logging October 3, 2025 15:18
@alehander92
Copy link
Member

alehander92 commented Oct 3, 2025

very impressive: but a radical approach: can't we somehow monkey patch the internal place/code that produces the writes? maybe this approach covers more fully/cleanly some cases, but it still seems a bit heavier

on the other hand: not critical, maybe for the future, but to check the current approach: what about file/other kind of events(in the future: network and others?) wouldn't we need something different for them, or would a similar approach be possible

@tzanko-matev
Copy link
Contributor Author

tzanko-matev commented Oct 3, 2025

I don't think that we can monkeypatch. We would need to detect all calls to C functions which deal with IO. But what if they are not from the standard library? For example our Rust module can produce logging statements which such an approach cannot handle.

Here we just redirect the in, out and error streams and we capture everything that we see.

It is possible to be even more ambitious on Linux using BPF. We can hook to the read and write syscalls. This means that we can map IO to which thread caused it. I am working on a prototype POC to test this approach as well.

@alehander92
Copy link
Member

ok, i have to try to understand it in more detail: will try to see/or ask next week; bpf sounds interesting, maybe it can help with the general case of IO events, but still not sure if we can match them to the actual step in the general case(and here)

@tzanko-matev tzanko-matev force-pushed the errors-and-logging branch 2 times, most recently from 5561ff3 to f4f5981 Compare October 15, 2025 11:29
Base automatically changed from errors-and-logging to main October 15, 2025 11:52
design-docs/capture-output-implementation-plan.md: 

Signed-off-by: Tzanko Matev <[email protected]>
design-docs/adr/0007-io-capture.md: 

Signed-off-by: Tzanko Matev <[email protected]>
New design docs
design-docs/adr/0008-line-aware-io-capture.md: 
design-docs/io-capture-line-proxy-implementation-plan.md: 
design-docs/prototypes/io_capture_ledger_mirror_prototype.py: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/src/runtime/frame_inspector.rs: 
codetracer-python-recorder/src/runtime/line_snapshots.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/src/runtime/io_lines.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/src/runtime/io_lines.rs: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/src/runtime/io_capture/events.rs: 
codetracer-python-recorder/src/runtime/io_capture/install.rs: 
codetracer-python-recorder/src/runtime/io_capture/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink.rs: 
codetracer-python-recorder/src/runtime/io_lines.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 
design-docs/adr/0008-line-aware-io-capture.md: 
design-docs/io-capture-line-proxy-implementation-plan.md: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/Cargo.lock: 
codetracer-python-recorder/Cargo.toml: 
codetracer-python-recorder/src/ffi.rs: 
codetracer-python-recorder/src/policy.rs: 
codetracer-python-recorder/src/runtime/io_capture/events.rs: 
codetracer-python-recorder/src/runtime/io_capture/install.rs: 
codetracer-python-recorder/src/runtime/io_capture/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/mute.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink.rs: 
codetracer-python-recorder/src/runtime/logging.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 
codetracer-python-recorder/src/session.rs: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
README.md: 
codetracer-python-recorder/codetracer_python_recorder/cli.py: 
codetracer-python-recorder/tests/python/unit/test_cli.py: 
examples/README.md: 
examples/io_capture.py: 
examples/stdin_capture.py: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/Cargo.lock: 
codetracer-python-recorder/Cargo.toml: 
codetracer-python-recorder/src/runtime/mod.rs: 
design-docs/adr/0008-line-aware-io-capture.md: 
design-docs/io-capture-line-proxy-implementation-plan.md: 

Signed-off-by: Tzanko Matev <[email protected]>
README.md: 
codetracer-python-recorder/Cargo.lock: 
codetracer-python-recorder/Cargo.toml: 
codetracer-python-recorder/src/policy.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror.rs: 
codetracer-python-recorder/src/runtime/io_capture/install.rs: 
codetracer-python-recorder/src/runtime/io_capture/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 
design-docs/adr/0008-line-aware-io-capture.md: 
design-docs/io-capture-line-proxy-implementation-plan.md: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/controller.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/ledger.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/stub.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/unix.rs: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror.rs: 
codetracer-python-recorder/src/runtime/io_capture/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/pipeline.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies/common.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies/input.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies/output.rs: 
codetracer-python-recorder/src/runtime/io_capture/proxies.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink/batcher.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink/enricher.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink/mod.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink/types.rs: 
codetracer-python-recorder/src/runtime/io_capture/sink.rs: 
codetracer-python-recorder/src/runtime/mod.rs: 

Signed-off-by: Tzanko Matev <[email protected]>
README.md: 
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/unix.rs: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
codetracer-python-recorder/CHANGELOG.md: 
design-docs/io-capture-line-proxy-implementation-plan.status.md: 

Signed-off-by: Tzanko Matev <[email protected]>
@tzanko-matev
Copy link
Contributor Author

This is a complete rewrite of the io-capture feature.
It uses proxies to capture stdin/stdout/stderr.
For unix it also tries to capture output which doesn't go through the standart Python objects. Still haven't tested it on Windows

@tzanko-matev tzanko-matev marked this pull request as ready for review October 15, 2025 15:57
Copy link

Coverage Summary

Rust (lines)
80.9% covered (5,134 / 6,350 | 1,216 missed)

File Lines Miss Cover
codetracer-python-recorder/src/code_object.rs 117 16 86.3%
codetracer-python-recorder/src/ffi.rs 191 19 90.1%
codetracer-python-recorder/src/lib.rs 15 15 0.0%
codetracer-python-recorder/src/logging.rs 478 80 83.3%
codetracer-python-recorder/src/monitoring/tracer.rs 794 221 72.2%
codetracer-python-recorder/src/policy.rs 350 59 83.1%
codetracer-python-recorder/src/runtime/activation.rs 117 9 92.3%
codetracer-python-recorder/src/runtime/frame_inspector.rs 148 63 57.4%
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/unix.rs 376 79 79.0%
codetracer-python-recorder/src/runtime/io_capture/pipeline.rs 74 10 86.5%
codetracer-python-recorder/src/runtime/io_capture/proxies/common.rs 159 62 61.0%
codetracer-python-recorder/src/runtime/io_capture/proxies/input.rs 128 91 28.9%
codetracer-python-recorder/src/runtime/io_capture/proxies/output.rs 41 27 34.1%
codetracer-python-recorder/src/runtime/io_capture/sink/batcher.rs 238 21 91.2%
codetracer-python-recorder/src/runtime/io_capture/sink/enricher.rs 73 17 76.7%
codetracer-python-recorder/src/runtime/mod.rs 1,672 221 86.8%
codetracer-python-recorder/src/runtime/output_paths.rs 98 16 83.7%
codetracer-python-recorder/src/runtime/value_capture.rs 102 66 35.3%
codetracer-python-recorder/src/session.rs 73 73 0.0%
codetracer-python-recorder/src/session/bootstrap.rs 183 14 92.3%
Showing top 20 entries by missed lines (of 31 total).

Python (statements)
72.6% covered (188 / 259 | 71 missed)

File Stmts Miss Cover
codetracer-python-recorder/codetracer_python_recorder/__init__.py 7 0 100.0%
codetracer-python-recorder/codetracer_python_recorder/__main__.py 2 2 0.0%
codetracer-python-recorder/codetracer_python_recorder/api.py 5 0 100.0%
codetracer-python-recorder/codetracer_python_recorder/auto_start.py 22 9 59.1%
codetracer-python-recorder/codetracer_python_recorder/cli.py 134 58 56.7%
codetracer-python-recorder/codetracer_python_recorder/formats.py 13 1 92.3%
codetracer-python-recorder/codetracer_python_recorder/session.py 76 1 98.7%

Generated automatically via generate_coverage_comment.py.

@alehander92
Copy link
Member

looks good: if it manages to match steps correctly on flushing / after step as i saw some code, it should be probably ok: not sure how much the overhead is, but this will be probably easily tested when tried with real useful programs

@tzanko-matev
Copy link
Contributor Author

@codex review this

Copy link

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@metacraft-labs metacraft-labs deleted a comment from github-actions bot Oct 15, 2025
@metacraft-labs metacraft-labs deleted a comment from github-actions bot Oct 15, 2025
@alehander92
Copy link
Member

alehander92 commented Oct 15, 2025

Chef's kiss.

Now the agents even try to kiss us.

@tzanko-matev tzanko-matev merged commit a57d961 into main Oct 16, 2025
6 checks passed
@tzanko-matev tzanko-matev deleted the io-capture branch October 16, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants